@extends('admin.layout.main')
@section('content')
    <!-- iCheck for checkboxes and radio inputs -->
    <link rel="stylesheet" href="{{asset('/adminlte/plugins/iCheck/all.css')}}">
    <section class="content-header">
      <h1>
        比赛列表
      </h1>
      <ol class="breadcrumb">
        <li><a href="javascript:void(0)"><i class="fa fa-dashboard"></i> 世界杯竞猜</a></li>
      </ol>
    </section>
    <section class="content">
        <!-- Small boxes (Stat box) -->
        <div class="row">
            <div class="col-lg-12 col-xs-6">
                <div class="box">
                    <div class="box-header with-border">
                        <div class="row">
                            <div class="col-sm-10">
                                <a href="javascript:void(0)" class="add-match"><i class="fa fa-fw fa-plus"></i>新增比赛</a>
                            </div>
                        </div>
                    </div>
                    
                    <!-- /.box-header -->
                    <div class="box-body">
                        <table class="table table-bordered table-hover" id="user-list">
                            <div class="dataTables_filter">
                                <form action="" method="GET">
                                      <button type="submit" class="btn btn-info btn-sm">查询:</button>
                                      <button type="button" class="btn btn-default" id="daterange-btn">
                                        <span>
                                          <i class="fa fa-calendar"></i>
                                        </span>
                                        <i class="fa fa-caret-down"></i>
                                      </button>
                                    <input type="hidden" name="time">
                                </form>
                            </div>
                            <thead>
                                <tr>
                                    <th>主队</th>
                                    <th>客队</th>
                                    <th>比赛时间</th>
                                    <th>比赛级别</th>
                                    <th>竞猜人数</th>
                                    <th>获奖人数</th>
                                    <th>比赛结果</th>
                                    <th>开奖状态</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody> 
                                @foreach($datas as $data)
                                    <tr id="{{$data->id}}">
                                        <td><img style="width:20px" src="/image/flag/{{$data->home}}.png"> {{$country_arr[$data->home]}}</td>
                                        <td><img style="width:20px" src="/image/flag/{{$data->away}}.png"> {{$country_arr[$data->away]}} </td>
                                        <td>{{date('Y-m-d H:i:s', $data->match_time)}}</td>
                                        <td>
                                            @if($data->level == 1)
                                                小组赛
                                            @elseif($data->level == 2)
                                                1/16决赛
                                            @elseif($data->level == 3)
                                                1/8决赛
                                            @elseif($data->level == 4)
                                                1/4决赛
                                            @elseif($data->level == 5)
                                                季军决赛
                                            @elseif($data->level == 6)
                                                冠军决赛
                                            @endif
                                        </td>
                                        <td><a><i class="fa fa-fw fa-search ptcp-num"></i></a> {{$data->ptcpNum->count()}}</td>
                                        <td><a><i class="fa fa-fw fa-search win-num"></i></a> {{$data->winNum->count()}}</td>
                                        <td>
                                            @if($data->match_result == 0)
                                                未开赛
                                            @elseif($data->match_result == 1)
                                                主队胜
                                            @elseif($data->match_result == 2)
                                                客队胜
                                            @elseif($data->match_result == 3)
                                                平局
                                            @endif
                                        </td>
                                        <td>
                                            @if($data->status == 0)
                                                未开将
                                            @elseif($data->status == 1)
                                                已开奖
                                            @elseif($data->status == 2)
                                                待开奖
                                            @endif
                                        </td>
                                        <td>
                                            <a href="javascript:void(0)" class="edit-match"><i class="fa fa-fw fa-eye"></i>详情</a>
                                            @if($data->status != 1)
                                                <a href="javascript:void(0)" class="edit-reward"><i class="fa fa-fw fa-diamond"></i>设置奖励</a>
                                            @endif
                                            <a href="javascript:void(0)" class="send-match"><i class="fa fa-fw fa-send"></i>发放奖励</a>
<!--                                             @if($data->status == 0)
                                                <a href="/admin/worldcup/begin_guess/{{$data->id}}"><i class="fa fa-fw fa-hand-paper-o"></i>开始竞猜</a>
                                            @endif -->
                                            <a href="javascript:void(0)" class="send-voice"><i class="fa fa-fw fa-volume-up"></i>消息通知</a>
                                        </td>
                                    </tr>
                                @endforeach
                            </tbody>
                        </table>
                        {{$datas->links()}}
                    </div>
                </div>
            </div>
        </div>
    </section>
    <!-- datepicker -->
    <script src="{{asset('/adminlte/plugins/datepicker/bootstrap-datepicker.js')}}"></script>
    <!-- iCheck 1.0.1 -->
    <script src="{{asset('/adminlte/plugins/iCheck/icheck.min.js')}}"></script>
    <script type="text/javascript">
        $(function () {
            //Date range as a button
            $('#daterange-btn').daterangepicker(
                {
                  ranges: {
                    '今天': [moment(), moment().add(1, 'days')],
                    '昨天': [moment().subtract(1, 'days'), moment()],
                    '最近7天': [moment().subtract(6, 'days'), moment().add(1, 'days')],
                    '最近30天': [moment().subtract(29, 'days'), moment().add(1, 'days')],
                    '本月': [moment().startOf('month'), moment().endOf('month')],
                    '上月': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
                  },
                  startDate: moment().subtract(29, 'days'),
                  endDate: moment()
                },
                function (start, end) {
                  $('#daterange-btn span').html(start.format('YYYY-MM-DD') + ' ~ ' + end.format('YYYY-MM-DD'));
                  $("input[name = time]").val(start.format('YYYY-MM-DD') + ' ~ ' + end.format('YYYY-MM-DD'));
                }
            );
        });

        $('.all_check').click(function(){
            $('.checkbox_member').click();
        });

        $(".add-match").click(function(){
            dialog_params('/admin/worldcup/create', '新增比赛');
        });

        $('.edit-match').click(function(){
            var id = $(this).parents('tr').attr('id');
            dialog_params('/admin/worldcup/edit/'+id, '编辑比赛');
        });

        $('.send-match').click(function(){
            var id = $(this).parents('tr').attr('id');
            dialog_params('/admin/worldcup/result/'+id, '发放奖励');
        });

        $('.edit-reward').click(function(){
            var id = $(this).parents('tr').attr('id');
            dialog_params('/admin/worldcup/edit_reward/'+id, '设置奖励');
        });

        $('.send-voice').click(function(){
            dialog_group('/admin/worldcup/send_voice', '消息通知');
        });

        $('.ptcp-num').click(function(){
            var id = $(this).parents('tr').attr('id');
            dialog_group('/admin/worldcup/ptcp_detail/'+id, '竞猜用户');
        });

        $('.win-num').click(function(){
            var id = $(this).parents('tr').attr('id');
            dialog_group('/admin/worldcup/win_detail/'+id, '获奖用户');
        });
    </script>
@endsection  